package com.lashou.chunshen.lashoutuangou.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lashou.chunshen.lashoutuangou.R;
import com.lashou.chunshen.lashoutuangou.bean.HomeCategory;
import com.lashou.chunshen.lashoutuangou.tools.PicassoUtils;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by Administrator on 2016/8/30.
 */
public class HomeSpecialGvAdapter extends BaseAdapter {
    List<HomeCategory.ResultsBean> datas;
    private Activity mActivity;
    public HomeSpecialGvAdapter(Activity activity,List<HomeCategory.ResultsBean> datas) {
        mActivity = activity;
        this.datas = datas;
    }

    @Override public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolderClass holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mActivity).inflate(R.layout.home_category, null, false);
            holder = new ViewHolderClass(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolderClass) convertView.getTag();
        }
        HomeCategory.ResultsBean bean = (HomeCategory.ResultsBean) getItem(position);
        if (null != bean) {
            PicassoUtils.loadImageViewHolder(mActivity,bean.getImg_url(),R.drawable.home_class_default_icon,holder.imageView);
            holder.textView.setText(bean.getCate_name());
        }

        return convertView;
    }
    public class ViewHolderClass {
        @InjectView(R.id.iv_home_category)
        ImageView imageView;
        @InjectView(R.id.tv_home_category)
        TextView textView;
        public ViewHolderClass(View view) {
            ButterKnife.inject(this, view);
        }
    }
}